<template>
  <div class="innerPageTable-box-OneTwo value-set-list-wrap innerPageTable-out-flex">
    <InnerPageTable ref="valueSetTable" :config="pageTableConfig">
      <div slot="table-bar" v-if="!isView">
        <RPButton :disabled="createDisabled" optType="create" type="info" text="新建" @click="goPlanCreatePage" />
      </div>
    </InnerPageTable>
  </div>
</template>

<script>
import dataFill from './dataFIll.vue'
import { columnList } from './columns'
import dataEleApi from '@/api/dataElement'
import coverApi from '@/api/cover.js'

export default {
  data() {
    return {
      createDisabled: false,
      searchForm: {},
      pageTableConfig: {
        loadDataFn: this.getServiceList,
        columns: columnList.bind(this)(this.isView),
        autoFirst: false, //默认 就是 false, 要配置在这里
        onSelectionChange: this.onSelectionChange,
        // border: true,
        pageSize: 100
      }
    }
  },
  props: {
    isView: {
      type: Boolean,
      default: false
    }
  },
  methods: {
    goPlanCreatePage() {
      new this.$sidelipPage(
        dataFill,
        {
          props: {
            isCreate: true
          }
        },
        data => {
          data && this.searchValueSet()
        }
      )
    },
    searchValueSet(pageNum = null) {
      this.$refs['valueSetTable'].load()
    },
    getServiceList(tableObj) {
      let { responseProcess, param } = tableObj
      let { pageNum, pageSize } = param
      const buCode =
        this.isView || this.$store.state.userBuByDataEle.key === 'CRC' ? '' : this.$store.state.userBuByDataEle.key
      dataEleApi.getAllData({ currentPage: pageNum, pageSize, buCode }).then(res => {
        let { size, total, current, records, pages } = res.data
        responseProcess({
          pageNum: current,
          pageSize: size,
          pages: pages,
          records: records || [],
          total: total
        })
      })
    },
    goDetail(row) {
      new this.$sidelipPage(
        dataFill,
        {
          props: {
            isView: this.isView,
            disabled: true,
            id: row.id || ''
          }
        },
        data => {
          data && this.searchValueSet()
        }
      )
    },
    goEdit(row) {
      new this.$sidelipPage(
        dataFill,
        {
          props: {
            id: row.id || '',
            isEdit: true
          }
        },
        data => {
          data && this.searchValueSet()
        }
      )
    },
    goApproval(row) {
      coverApi.getProcessUrl({ id: row.processId, deviceType: 'PC' }).then(res => {
        window.open(res.data.data)
      })
      setTimeout(() => {
        this.$emit('Close', 1)
      }, 1000)
    }
  },
  mounted() {
    this.searchValueSet()
  }
}
</script>

<style lang="less" scoped></style>
